<?php

/**
 * MVM_MALL 网上商店系统  商品设置管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-02-27 $
 * $Id: settings.inc.php www.mvmmall.com$
 * ---------------------------------------------
*/

if (!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if ($setp==1 && $_POST){
//把不存在的数据库配置值写入数据库
$query = $db->query("SELECT * FROM `{$tablepre}config`");
while ($rt = $db->fetch_array($query)){
    $rt['cf_name']         = str_replace("'","\'",$rt['cf_name']);
    $rt_cf[$rt['cf_name']] = $rt['cf_value'];
}
//图片设置
if ($type=='img_set' || $type=='all') {
	!$config['mm_thumb_wate'] ? $config['mm_thumb_wate'] = 0:(int)$config['mm_thumb_wate'];
	!$config['mm_big_wate']   ? $config['mm_big_wate']   = 0:(int)$config['mm_big_wate'];
}
//短信设置
if ($type=='sms_set' || $type=='all') {
	!$config['mm_sms_member']    ? $config['mm_sms_member']   = 0:(int)$config['mm_sms_member'];
	!$config['mm_sms_order']     ? $config['mm_sms_order']    = 0:(int)$config['mm_sms_order'];
	!$config['mm_sms_receipt']   ? $config['mm_sms_receipt']  = 0:(int)$config['mm_sms_receipt'];
	!$config['mm_sms_delivery']  ? $config['mm_sms_delivery'] = 0:(int)$config['mm_sms_delivery'];
}
//邮件设置
if ($type=='email_set' || $type=='all') {
	!$config['mm_mail_member']    ? $config['mm_mail_member']   = 0:(int)$config['mm_mail_member'];
	!$config['mm_mail_order']     ? $config['mm_mail_order']    = 0:(int)$config['mm_mail_order'];
	!$config['mm_mail_receipt']   ? $config['mm_mail_receipt']  = 0:(int)$config['mm_mail_receipt'];
	!$config['mm_mail_delivery']  ? $config['mm_mail_delivery'] = 0:(int)$config['mm_mail_delivery'];
}
//伪静态如果变更后，更新导航条缓存
$config['rewrite'] !==$rewrite && $rewrite=$config['rewrite']; $cache->put_cache('nav');

foreach ($config as $key => $value) {
    if ($rt_cf[$key]!=$value) {
        $cf_name     = $db->get_value("SELECT cf_name FROM `{$tablepre}config` WHERE cf_name='$key'");
        if ($cf_name) {
            $db->query("UPDATE `{$tablepre}config` SET cf_value='$value' WHERE cf_name='$key'");
        } else {
            $db->query("INSERT INTO `{$tablepre}config` (cf_name,cf_value) VALUES ('$key','$value')");
        }
    }
}
$cache->put_cache('cfg');
admin_msg('success',dreferer()); 
} else { 
    //基础设置
   if ($type=='basis' || $type=='all') {
    $lang_menu    = drop_menu(lang_arr(),'config[mm_lang]',$mm_lang);
   	$tplpath_menu = drop_menu(tpl_array(),'config[mm_skin_name]',$mm_skin_name);
   	drop_check($mm_obstart,'mm_obstart');
   	drop_check($rewrite,'rewrite');
   	drop_check($mm_mall_form,'mm_mall_form');
   	drop_check($mm_rewrite,'mm_rewrite');
   }    	
   //图片设置
   if ($type=='img_set' || $type=='all')  {
       drop_check($mm_thumb_wate,'mm_thumb_wate');
       drop_check($mm_big_wate,'mm_big_wate');
       drop_check($mm_wate_class,'mm_wate_class');
       drop_check($mm_wate_class,'mm_wate_class');
   }
    //注册设置
     if ($type=='reg_set' || $type=='all')  {
        drop_check($mm_member_reg,'mm_member_reg');
        drop_check($mm_term,'mm_term');
        drop_check($mm_reg_code,'mm_reg_code');
        drop_check($mm_login_code,'mm_login_code');
        $grade_menu = drop_menu($cache->get_cache('grade'),'config[mm_grade]',$mm_grade);
    }
    //营销推
    if ($type=='info_set' || $type=='all') {
    	 drop_check($mm_extend,'mm_extend');
    	 drop_check($mm_monysetup,'mm_monysetup');
    }
    //积分设置
    if ($type=='point_set' || $type=='all') {
        drop_check($mm_point_use,'mm_point_use');
        drop_check($mm_barter_use,'mm_barter_use');
        $arr = array('2'=>$lang['order_status'][2],'4'=>$lang['order_status'][4],'7'=>$lang['order_status'][7]);
        $point_menu = drop_menu($arr,'config[mm_point_method]',$mm_point_method);
    }
    //库存
    if ($type=='stock_set' || $type=='all') {
        drop_check($mm_stock_use,'mm_stock_use');
        drop_check($mm_barter_use,'mm_barter_use');
        $stock_menu = drop_menu(array('1'=>'支付确定','2'=>'商品发送完成','3'=>'采购完成'),'config[mm_stock_method]',$mm_stock_method);
    }
     //短信
    if ($type=='sms_set' || $type=='all') {
        drop_check($mm_sms_use,'mm_sms_use');
        drop_check($mm_sms_useadmin,'mm_sms_useadmin');
        drop_check($mm_sms_member,'mm_sms_member');
        drop_check($mm_sms_order,'mm_sms_order');
        drop_check($mm_sms_receipt,'mm_sms_receipt');
        drop_check($mm_sms_delivery,'mm_sms_delivery');
    }
    //邮件
    if ($type=='email_set' || $type=='all') {
        drop_check($mm_mail_smtpauth,'mm_mail_smtpauth');
        drop_check($mm_mail_member,'mm_mail_member');
        drop_check($mm_mail_order,'mm_mail_order');
        drop_check($mm_mail_receipt,'mm_mail_receipt');
        drop_check($mm_mail_delivery,'mm_mail_delivery');
        $emil_menu = drop_menu(array('SMTP','mail_method','send_mail'),'config[mm_mail_method]',$mm_mail_method);

    }
    //显示设置
    if ($type=='show_set' || $type=='all') {
        drop_check($mm_price_length,'mm_price_length');
        drop_check($mm_mail_member,'mm_mail_member');
        $mm_use_vat ==1 ? $mm_use_vat_y='checked' : '';
        $mm_use_vat ==2 ? $mm_use_vat_n='checked' : '';
        drop_check($mm_comment_app,'mm_comment_app');
        drop_check($mm_comment_code,'mm_comment_code');
        drop_check($mm_history_type,'mm_history_type');
        drop_check($mm_other_code,'mm_other_code');
        drop_check($mm_close,'mm_close');
        $show_price_menu = drop_menu(array('1'=>'全部显示','2'=>'独立显示','3'=>'按权限显示'),'config[mm_show_price]',$mm_show_price);
       $mm_footer_code = stripslashes($mm_footer_code);
    }
    //其他设置
    if ($type=='other_set' || $type=='all') {
       
    }
   //$style_array = style_cache();
   require_once template('settings');
   footer();  
}

function lang_arr() {
    $m_mall_skin = get_dirinfo(MVMMALL_ROOT.'./language/');
    for($i =0 ; $i<count($m_mall_skin) ; $i++) {
       $arr[$m_mall_skin[$i]] = $m_mall_skin[$i];
    }
    return $arr;
}
